import 'package:pornhub_app/components/tab_bar_indicator/tab_indicator.dart';
import 'package:pornhub_app/utils/color.dart';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:pornhub_app/views/mine/buy/views/mine_short_video_list.dart';

import '../favorite/views/favorite_community.dart';
import '../favorite/views/favorite_video_page.dart';

class MineBuyPage extends StatelessWidget {
  MineBuyPage({super.key});

  final List tabs = ['视频', '帖子', '游戏', '抖阴'];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: _buildAppBar(context),
      body: Column(
        children: <Widget>[
          Expanded(
            child: _buildContentView(context),
          ),
        ],
      ),
    );
  }

  AppBar _buildAppBar(BuildContext context) {
    return AppBar(
      leading: IconButton(
        iconSize: 20.w,
        icon: const Icon(
          Icons.arrow_back_ios,
          color: Colors.grey,
        ),
        onPressed: () => onBackClick(context),
      ),
      title: Text("我的购买",
          textAlign: TextAlign.center,
          style: TextStyle(
            color: COLOR.hexColor("#ffffff"),
            fontSize: 17.w,
            fontWeight: FontWeight.w600,
          )),
      centerTitle: true,
      bottom: PreferredSize(
        preferredSize: const Size.fromHeight(0.5),
        child: Container(
          height: 1,
          color: COLOR.hexColor("#F0F0F0"),
        ),
      ),
    );
  }

  Widget _buildContentView(BuildContext context) {
    return DefaultTabController(
      length: tabs.length,
      child: Column(
        children: <Widget>[
          Padding(
            padding: EdgeInsets.only(left: 5.w, right: 100.w),
            child: TabBar(
              tabs: tabs.map((e) => Tab(text: e)).toList(),
              dividerHeight: 0,
              labelStyle: TextStyle(
                color: COLOR.hexColor("#D8201D"),
                fontSize: 15.sp,
                fontWeight: FontWeight.w700,
              ),
              unselectedLabelStyle: TextStyle(
                color: COLOR.hexColor("#666666"),
                fontSize: 15.sp,
                fontWeight: FontWeight.w400,
              ),
              indicator: TabIndicator(
                borderSide:
                    BorderSide(width: 3.w, color: COLOR.hexColor("#DD001B")),
                indicatorBottom: 10.w,
                indicatorWidth: 10.w,
              ),
            ),
          ),
          Expanded(
            child: TabBarView(
              children: tabs.map((_) {
                if (_ == "视频") {
                  return const FavoriteVideoPage();
                }
                if (_ == '帖子') {
                  return const FavoriteCommunity();
                }
                if (_ == '抖阴') {
                  return const MineShortVideoList(isbuy: true);
                }
                return const SizedBox.shrink();
              }).toList(),
            ),
          ),
        ],
      ),
    );
  }

  void onBackClick(BuildContext context) {
    Navigator.pop(context);
  }
}
